<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/juqery.js"></script>
    <style>
      
        .goback{
            width: 130px;
            height: 40px;
            background-color: pink;
            text-align: center;
            line-height: 40px;
            /* margin-top: 400px;
            margin-left: 1000px; */
            position: absolute;
            top: 700px;
            left: 750px;
            display: none;
        }
        .container{
            width: 500px;
            height: 800px;
            background-color: cadetblue;
            margin: 300px 200px;
            position: relative;
        }
    </style>
</head>
<body>
    <div class="goback">返回顶部</div>
    <div class="container"></div>
</body>
<script>
    $(function(){
        $(window).scroll(function(){
            var boxtop =$(document).scrollTop
            console.log(boxtop);
            if($(".container").scrollTop>=boxtop){
                $(".goback").fadeIn()
            }else{
                $(".goback").fadeOut()
            }
        })
        $(".goback").click(function(){
            $("body,html").stop().animate({
                scrollTop:0
            })
        })
    })
</script>
</html>